<template>
	<view class="login-view col-arrange">
		<view class="logo-box">
			<image class="l-logo" src="../../static/logo.png"></image>
		</view>
		<!-- <view><text class="tip-text">用户名：</text> </view>-->
		<input id="username" class="theme-input" type="text" v-model="username" placeholder="请输入用户名">
		<!-- <view><text class="tip-text">密&nbsp;&nbsp;&nbsp;&nbsp;码：</text> </view>-->
		<input id="password" class="theme-input" password="true" v-model="password" placeholder="请输入密码">
		<!-- <view><text class="tip-text" style="color:red">{{errorText}}</text></view> -->
		<button id="lb" type="primary" @click="submit">登录</button>
		<view><button type="primary" @click="register">前往注册</button></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				username : '',
				password : '',
				errorText : "",
				nextUrl : "main"
			}
		},
		onLoad(option) {
			if(option.nextUrl != null){
				this.nextUrl = option.nextUrl;
				
			}else{
				uni.getStorage({
					key : 'userToken',
					success :function(res){
						var data = res.data;
						if(data != null){
							uni.navigateTo({
								url : "./main"
							})
						}

					},
					fail : function(){
					}
				});
			}
		},
		methods: {
			
			submit : function(){
				if(this.username == "" || this.password == ""){
					uni.showModal({
						title : '错误',
						content : '关键信息不可为空',
						showCancel : false
					})
					return;
				}
				var param = {'username':this.username,'password':this.password};
				// console.log(param);
				var vm = this;
				this.$post(this.userurl + '/user/login',param,function(res){
					var data = res.data;
					if(data.code != 0){
						// vm.errorText = data.message;
						uni.showModal({
							title : '错误',
							content : data.message,
							showCancel : false
						})
						return;
					}
					var token = {'userId' : param.username , 'token' : data.token};
					// console.log(token);
					uni.setStorage({
						key : 'userToken',
						data : token
					})
					// 到达用户个人页面
					uni.navigateTo({
						url : vm.nextUrl
					})
				},true);
				
			},
			register : function(){
				uni.navigateTo({
					url : 'register'
				})
			}
		}
	}
</script>

<style>
	@import "../../common/zcss.css";
	/* page{
		position: relative;
	} */
	.login-view{
		top:200upx;
		left:150upx;
		/* text-align: center; */
		position: absolute;
	}
	/* page{
		background-color: white;
	} */
	button{
		margin-top: 20upx;
		/* margin-bottom: 300upx; */
		background-color: blue;
		width: 440upx; 
		border-radius: 50upx;
	}
	input{
		margin-top:25upx;
		margin-bottom: 25upx;
		/* background-color: rgba(231, 226, 226, 0.568); */
		
		height:40upx;
		width: 400upx;
		padding: 20upx;
		padding-left: 30upx;
		border-radius: 50upx;
		/* border-bottom: 1upx solid black; */
	}
	.l-logo {
		margin-left: 80upx;
		margin-bottom: 100upx;
		width: 300upx;
		height: 300upx;
		border-radius: 300upx;
	}
		
	
	
</style>
